home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 with MFC / Programming Windows 95 with MFC (Microsoft Programming Series)(097-0001465)(1996).iso / CODE / Chap09 / Paint7 / MainFrame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-05  |  1.8 KB  |  67 lines

  1. //***********************************************************************
  2. //
  3. //  MainFrame.cpp
  4. //
  5. //***********************************************************************
  6.  
  7. #define OEMRESOURCE
  8.  
  9. #include <afxwin.h>
  10. #include "Resource.h"
  11. #include "CLine.h"
  12. #include "MainFrame.h"
  13. #include "Paint7Doc.h"
  14.  
  15. IMPLEMENT_DYNCREATE (CMainFrame, CMDIFrameWnd)
  16.  
  17. BEGIN_MESSAGE_MAP (CMainFrame, CMDIFrameWnd)
  18.     ON_WM_CREATE ()
  19.     ON_WM_MEASUREITEM ()
  20.     ON_WM_DRAWITEM ()
  21. END_MESSAGE_MAP ()
  22.  
  23. void CMainFrame::OnMeasureItem (int nIDCtl, LPMEASUREITEMSTRUCT lpmis)
  24. {
  25.     lpmis->itemWidth = ::GetSystemMetrics (SM_CYMENU) * 4;
  26.     lpmis->itemHeight = ::GetSystemMetrics (SM_CYMENU);
  27. }
  28.  
  29. void CMainFrame::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpdis)
  30. {
  31.     BITMAP bm;
  32.     CBitmap bitmap;
  33.     bitmap.LoadOEMBitmap (OBM_CHECK);
  34.     bitmap.GetObject (sizeof (bm), &bm);
  35.  
  36.     CDC dc;
  37.     dc.Attach (lpdis->hDC);
  38.  
  39.     CBrush* pBrush = new CBrush (::GetSysColor ((lpdis->itemState &
  40.         ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_MENU));
  41.     dc.FrameRect (&(lpdis->rcItem), pBrush);
  42.     delete pBrush;
  43.  
  44.     if (lpdis->itemState & ODS_CHECKED) {
  45.         CDC dcMem;
  46.         dcMem.CreateCompatibleDC (&dc);
  47.         CBitmap* pOldBitmap = dcMem.SelectObject (&bitmap);
  48.  
  49.         dc.BitBlt (lpdis->rcItem.left + 4, lpdis->rcItem.top +
  50.             (((lpdis->rcItem.bottom - lpdis->rcItem.top) -
  51.             bm.bmHeight) / 2), bm.bmWidth, bm.bmHeight, &dcMem,
  52.             0, 0, SRCCOPY);
  53.  
  54.         dcMem.SelectObject (pOldBitmap);
  55.     }
  56.  
  57.     pBrush = new CBrush (CPaintDoc::m_crColors[lpdis->itemID -
  58.         ID_COLOR_BLACK]);
  59.     CRect rect = lpdis->rcItem;
  60.     rect.DeflateRect (6, 4);
  61.     rect.left += bm.bmWidth;
  62.     dc.FillRect (rect, pBrush);
  63.     delete pBrush;
  64.  
  65.     dc.Detach ();
  66. }
  67.